<?
/**
 * Error controller
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @category VaselinEngine
 * @package Default Module
 * @subpackage Controller
 * @license  New BSD License
 *
 */
class ErrorController extends Zend_Controller_Action {
	
	/**
	 * This action handles
	 *    - Application errors
	 *    - Errors in the controller chain arising from missing
	 *     controller classes and/or action methods
	 */
	public function errorAction() {
		
		$module = $this->_request->getParam('module');
		$errors = $this->_getParam ( 'error_handler' );
		
		switch ( $errors->type) {
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER :
			case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION :

						
				
				$this->getResponse ()->setRawHeader ( 'HTTP/1.1 404 Not Found' );				
				$view = Zend_Registry::get ( 'view' );
				$this->getResponse()->sendHeaders();
				echo $view->fetch('404.tpl');
				
				if('admin'===$module){
					die;
				}

			break;
			default :
				$exception = $errors->exception;
				echo $exception->getMessage () . "\n" . $exception->getTraceAsString ();
			break;
		}
	}
}